using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class Status : MonoBehaviour
{
    public TextMeshProUGUI Name;
    public TextMeshProUGUI RootText;
    public TextMeshProUGUI FeatureText;
    public TextMeshProUGUI SpeedText;
    public TextMeshProUGUI RangeText;

    public TextMeshProUGUI BuffText;
    public GameObject BuffWindow;

    public Vector3 offset;

    private string[] speedString = { "零攻速", "非常慢", "慢", "一般", "快", "非常快" };

    public void ShowStatus(Pawn pawn, bool ifDraging)
    {
        if (!LevelManager.instance.ifCanCheckPawn)
        {
            gameObject.SetActive(false);
            return;
        }
        if (pawn == null || ifDraging)
        {
            gameObject.SetActive(false);
            return;
        }
        else
        {
            gameObject.SetActive(true);
        }

        Name.text = pawn.TestCardData.Name;

        SpeedText.text = speedString[(int)pawn.TestCardData.Speed];
        RangeText.text = pawn.Property.Range.ToString();

        //string featureText = "";
        //foreach (var feature in pawn.FeatureMono.Features)
        //{
        //    featureText += feature.Description;
        //    featureText += "  ";
        //}
        string featureText = pawn.TestCardData.Description;
        FeatureText.text = featureText;

        if (pawn.FeatureMono.Features.Count <= 0)
        {
            BuffWindow.SetActive(false);
        }
        else
        {
            BuffWindow.SetActive(true);
            string buffText = "\n";
            foreach (var feature in pawn.FeatureMono.Features)
            {
                buffText += feature.GetDescription();
                buffText += "\n";
            }
            BuffText.text = buffText;
        }

        //string rootsText = "";
        //foreach (var feature in pawn.Roots.RootsFeatures)
        //{
        //    rootsText += feature.Description;
        //    rootsText += "  ";
        //}
        //RootText.text = rootsText;

        var screenPosition = Camera.main.WorldToScreenPoint(pawn.transform.position);
        transform.position = screenPosition + offset;
    }

    public void ShowStatus(Pawn pawn)
    {
        if (pawn == null)
        {
            return;
        }

        Name.text = pawn.TestCardData.Name;

        CardData data = pawn.TestCardData;
        SpeedText.text = speedString[(int)pawn.TestCardData.Speed];
        RangeText.text = data.Range.ToString();

        BuffWindow.SetActive(false);

        //ֱ����pawn��carddata��description

        //string featureText = "Feature:\\n";
        //foreach (var feature in data.Features)
        //{
        //    if (feature == null)
        //        continue;
        //    featureText += feature.Description;
        //    featureText += "  ";
        //}
        //FeatureText.text = featureText;

        string featureText = pawn.TestCardData.Description;
        //foreach (var feature in data.RootFeatures)
        //{
        //    if (feature == null)
        //        continue;
        //    rootsText += feature.Description;
        //    rootsText += "  ";
        //}
        FeatureText.text = featureText;
    }


    /// <summary>
    /// Update is called every frame, if the MonoBehaviour is enabled.
    /// </summary>
    void Update()
    {

    }
}
